<template>
    <div>
        <h2>
           定义一个根store，统一管理其他模块的store
        </h2>
        user/name: {{name}}
        counter/count: {{count}}
        <button @click="changeName">修改name</button>
    </div>
</template>
<script setup lang='ts'>
import { storeToRefs } from 'pinia'
import { useStore } from './stores/index'
let store = useStore()
console.log('store', store)

// 使用store中的数据
const { name } = storeToRefs(store.user)
const { count } = store.counter

// 使用store中的数据2
// const { user: { name }, counter: { count }} = storeToRefs(store) // 错误

// 修改name
const changeName = () => {
    store.user.name = '王五'
console.log('store', store.user)
}
</script>


<style lang='scss' scoped>

</style>